import React ,{Suspense} from 'react'
import {Spin} from 'antd'
import {Switch,Route,Redirect} from 'react-router-dom'
import menus from './Menus'
import RedirectRouterView from './RedirectRouterView'

function RouterView(){
    const renderRoute=(menus)=>{
        return menus.map(item=>{
            if(item.children){
                return renderRoute(item.children)
            }else{
                return <Route 
                path={item.path}
                key={item.path}
                exact
                component={item.component}
                />
            }
        })
    }
    return (
        <Suspense fallback={<div className="loading"><Spin size="large" /></div>} >
          <Switch>
            <Redirect path='/' exact to='/home'/>
            {
              renderRoute(menus)
            }
             {
            <RedirectRouterView/>
            }
          </Switch>
         
        </Suspense>
     )
    
}
export default RouterView